var token;
var num;
var u_id;
//班级id，只需要传给Student.html
var c_id;
//隶属机构id
var i_id;

$(".toggle").on("click", function () {
    $(".container").stop().addClass("active");
});

$(".close").on("click", function () {
    $(".container").stop().removeClass("active");
});

$("#btn").click(function () {
    if ($("#num").val() == "" || $("#password").val() == "") {
        window.alert("学工号或密码不能为空");
        return;
    }

    $.ajax({
        contentType: 'application/json; charset=utf-8',
        type: "POST",
        url: "/api/user/login",
        data: JSON.stringify({
            "num": $("#num").val(),
            "password": $("#password").val(),
            "loginPosition": $(":radio:checked").val()
        }),
        success: function (result) {
            if (result.success) {
                token = result.data.token;
                num = result.data.userVo.num;
                u_id = result.data.userVo.id;
                c_id = result.data.userVo.clazzId;
                i_id = result.data.userVo.institutionId;
                // wsTest();
                if ($(":radio:checked").val() == "student") {
                    window.location.href = '/api/templates/Student.html?token=' + token + "&u_id=" + u_id + "&num=" + num + "&c_id=" + c_id
                }
                if ($(":radio:checked").val() == "teacher") {
                    window.location.href = '/api/templates/Teacher.html?token=' + token + "&u_id=" + u_id + "&num=" + num
                }
                if ($(":radio:checked").val() == "admin") {
                    window.location.href = '/api/templates/Admin.html?token=' + token + "&u_id=" + u_id + "&num=" + num + "&i_id=" + i_id
                }
                console.log(token)
            } else {
                window.alert(result.message);
            }
        }
    });
});


